<?php

namespace app\index\model;

use think\Model;

/**
 * 柜门
 * Class Door
 * @package app\index\model
 */
class Door extends Model
{
    public $autoWriteTimestamp = 'int';

    // 优先取用几个柜子
    public static $low_num_door = 5;

    // 柜子最多设备数量
    public static $max_device = 10;

    protected $append = [
        'device_category_text',
        'status_text',
        'lock_status_text',
    ];

    protected function getDeviceCategoryTextAttr($value,$data)
    {
        if (empty($data['device_category']))
            return '';
        $name = DeviceCategory::where('id',$data['device_category'])->value('name');
        return empty($name) ? '' : $name;
    }

    // 获取柜子状态说明
    public function getStatusTextAttr($value,$data)
    {
        $status_list = ['空', '正常', '已满'];

        if (empty($data['status']) || empty($status_list[$data['status']])) return '';

        return $status_list[$data['status']];
    }

    // 获取柜子状态说明
    public function getLockStatusTextAttr($value,$data)
    {
        if (!isset($data['lock_status']))
            return '未知';
        return $data['lock_status'] == 1 ? '开' : '关';
    }
}